# -*- python -*-
# ex: set syntax=python:

# This is a sample buildmaster config file. It must be installed as
# 'master.cfg' in your buildmaster's base directory (although the filename
# can be changed with the --basedir option to 'mktap buildbot master').

# It has one job: define a dictionary named BuildmasterConfig. This
# dictionary has a variety of keys to control different aspects of the
# buildmaster. They are documented in docs/config.xhtml .


# This is the dictionary that the buildmaster pays attention to. We also use
# a shorter alias to save typing.
c = BuildmasterConfig = {}

####### BUILDSLAVES

# the 'slaves' list defines the set of allowable buildslaves. Each element is
# a BuildSlave object, which is created with bot-name, bot-password.  These
# correspond to values given to the buildslave's mktap invocation.
from buildbot.buildslave import BuildSlave
c['slaves'] = [BuildSlave("D630-laptop", "123456", max_builds=1)]

# 'slavePortnum' defines the TCP port to listen on. This must match the value
# configured into the buildslaves (with their --master option)

c['slavePortnum'] = 9989

####### CHANGESOURCES

# the 'change_source' setting tells the buildmaster how it should find out
# about source code changes. Any class which implements IChangeSource can be
# put here: there are several in buildbot/changes/*.py to choose from.

from buildbot.changes.pb import PBChangeSource
c['change_source'] = PBChangeSource()

####### SCHEDULERS

## configure the Schedulers
c['schedulers'] = []

from buildbot.scheduler import Scheduler
from buildbot.scheduler import Nightly
c['schedulers'].append(Scheduler(name="openembedded gulessoft change building", branch="com.gulessoft.dev",
                                 treeStableTimer=20*60,
                                 builderNames=["oe_gss_inc_change_allinone"]))
c['schedulers'].append(Nightly(name="clean storcenter",
                                 hour=19, minute=50, dayOfMonth=range(1,31,5),
                                 builderNames=["cleanup_storcenter"]))
c['schedulers'].append(Nightly(name="clean titan",
                                 hour=19, minute=50, dayOfMonth=range(2,31,5),
                                 builderNames=["cleanup_titan"]))
c['schedulers'].append(Nightly(name="clean sun4cdm",
                                 hour=19, minute=50, dayOfMonth=range(3,31,5),
                                 builderNames=["cleanup_sun4cdm"]))
c['schedulers'].append(Nightly(name="clean qemumips",
                                 hour=19, minute=50, dayOfMonth=range(4,31,5),
                                 builderNames=["cleanup_qemumips"]))
c['schedulers'].append(Nightly(name="clean qemuarm",
                                 hour=19, minute=50, dayOfMonth=range(5,31,5),
                                 builderNames=["cleanup_qemuarm"]))

####### BUILDERS

# the 'builders' list defines the Builders. Each one is configured with a
# dictionary, using the following keys:
#  name (required): the name used to describe this builder
#  slavename (required): which slave to use (must appear in c['bots'])
#  builddir (required): which subdirectory to run the builder in
#  factory (required): a BuildFactory to define how the build is run
#  periodicBuildTime (optional): if set, force a build every N seconds

# buildbot/process/factory.py provides several BuildFactory classes you can
# start with, which implement build processes for common targets (GNU
# autoconf projects, CPAN perl modules, etc). The factory.BuildFactory is the
# base class, and is configured with a series of BuildSteps. When the build
# is run, the appropriate buildslave is told to execute each Step in turn.

# the first BuildStep is typically responsible for obtaining a copy of the
# sources. There are source-obtaining Steps in buildbot/steps/source.py for
# CVS, SVN, and others.
import copy
from buildbot.process              import factory
from buildbot.steps.shell          import Compile, ShellCommand 
from buildbot.steps                import source

defaultenv = {}

distros   = ['micro']
machines  = ['qemux86', 'qemuarm', 'qemumips', 'storcenter', 'titan', 'sun4cdm']
libcs 	  = ['glibc', 'eglibc', 'uclibc']
targets   = ['base-image']

repository="/opt/git/openembedded-gss.git"
oebranch="com.gulessoft.dev"

oe_gss_inc_change_allinone = factory.BuildFactory()

oe_gss_inc_change_allinone.addStep(source.Git(repourl=repository, branch=oebranch, mode='update', workdir='openembedded'))

for distro in distros:
	defaultenv['DISTRO'] = distro
	for machine in machines:
		defaultenv['MACHINE'] = machine
		for libc in libcs:
			defaultenv['LIBC'] = libc
			for target in targets:
				oe_gss_inc_change_allinone.addStep(ShellCommand, 
						description=["Building", defaultenv['DISTRO'],
							defaultenv['MACHINE'], defaultenv['LIBC'] , target], 
						command=["../../full-oe-autobuild", target], 
						env=copy.copy(defaultenv), 
						timeout=10000)

build_change = {
        'name':      "oe_gss_inc_change_allinone",
        'slavename': "D630-laptop",
        'builddir':  "oe_gss_inc_change_allinone",
        'factory':    oe_gss_inc_change_allinone,
}

c['builders'] = [build_change]

cleanup_storcenter = factory.BuildFactory()
cleanup_storcenter.addStep(ShellCommand, 
		description=["cleanup", "storcenter"], 
		command="""
	find ../../oe_gss_inc_change_allinone/build/tmp -maxdepth 4 -name 'storcenter*' -type d | xargs rm -r || true
		""", 
		timeout=10000)
cleanup_storcenter.addStep(ShellCommand, 
		description=["cleanup", "ppc603e"], 
		command="""
	find ../../oe_gss_inc_change_allinone/build/tmp -maxdepth 4 -name 'ppc603e*' -type d | xargs rm -r || true
		""", 
		timeout=10000)

clean_storcenter = {
        'name':      "cleanup_storcenter",
        'slavename': "D630-laptop",
        'builddir':  "cleanup_storcenter",
        'factory':    cleanup_storcenter,
}

c['builders'].append(clean_storcenter)

cleanup_titan = factory.BuildFactory()
cleanup_titan.addStep(ShellCommand, 
		description=["cleanup", "titan"], 
		command="""
		find ../../oe_gss_inc_change_allinone/build/tmp -maxdepth 4 -name 'titan*' -type d | xargs rm -r || true
		""", 
		timeout=10000)
cleanup_titan.addStep(ShellCommand, 
		description=["cleanup", "sh4"], 
		command="""
		find ../../oe_gss_inc_change_allinone/build/tmp -maxdepth 4 -name 'sh4*' -type d | xargs rm -r || true
		""", 
		timeout=10000)

clean_titan = {
        'name':      "cleanup_titan",
        'slavename': "D630-laptop",
        'builddir':  "cleanup_titan",
        'factory':    cleanup_titan,
}

c['builders'].append(clean_titan)

cleanup_sun4cdm = factory.BuildFactory()
cleanup_sun4cdm.addStep(ShellCommand, 
		description=["cleanup", "sun4cdm"], 
		command="""
	find ../../oe_gss_inc_change_allinone/build/tmp -maxdepth 4 -name 'sun4cdm*' -type d | xargs rm -r || true
		""", 
		timeout=10000)
cleanup_sun4cdm.addStep(ShellCommand, 
		description=["cleanup", "sparc"], 
		command="""
	find ../../oe_gss_inc_change_allinone/build/tmp -maxdepth 4 -name 'sparc*' -type d | xargs rm -r || true
		""", 
		timeout=10000)

clean_sun4cdm = {
        'name':      "cleanup_sun4cdm",
        'slavename': "D630-laptop",
        'builddir':  "cleanup_sun4cdm",
        'factory':    cleanup_sun4cdm,
}

c['builders'].append(clean_sun4cdm)

cleanup_qemumips = factory.BuildFactory()
cleanup_qemumips.addStep(ShellCommand, 
		description=["cleanup", "qemumips"], 
		command="""
	find ../../oe_gss_inc_change_allinone/build/tmp -maxdepth 4 -name 'qemumips*' -type d | xargs rm -r || true
		""", 
		timeout=10000)
cleanup_qemumips.addStep(ShellCommand, 
		description=["cleanup", "mips"], 
		command="""
	find ../../oe_gss_inc_change_allinone/build/tmp -maxdepth 4 -name 'mips*' -type d | xargs rm -r || true
		""", 
		timeout=10000)

clean_qemumips = {
        'name':      "cleanup_qemumips",
        'slavename': "D630-laptop",
        'builddir':  "cleanup_qemumips",
        'factory':    cleanup_qemumips,
}

c['builders'].append(clean_qemumips)

cleanup_qemuarm = factory.BuildFactory()
cleanup_qemuarm.addStep(ShellCommand, 
		description=["cleanup", "qemuarm"], 
		command="""
	find ../../oe_gss_inc_change_allinone/build/tmp -maxdepth 4 -name 'qemuarm*' -type d | xargs rm -r || true
		""", 
		timeout=10000)
cleanup_qemuarm.addStep(ShellCommand, 
		description=["cleanup", "armv5te"], 
		command="""
	find ../../oe_gss_inc_change_allinone/build/tmp -maxdepth 4 -name 'armv5te*' -type d | xargs rm -r || true
		""", 
		timeout=10000)

clean_qemuarm = {
        'name':      "cleanup_qemuarm",
        'slavename': "D630-laptop",
        'builddir':  "cleanup_qemuarm",
        'factory':    cleanup_qemuarm,
}

c['builders'].append(clean_qemuarm)

####### STATUS TARGETS

# 'status' is a list of Status Targets. The results of each build will be
# pushed to these targets. buildbot/status/*.py has a variety to choose from,
# including web pages, email senders, and IRC bots.

c['status'] = []

# Use allowForce=True (boolean, not a string. ie: not 'True') to allow
# Forcing Builds in the Web User Interface. The default is False.
from buildbot.status import html
#uncomment the following to enable BasicAuth
#from buildbot.status.web.auth import BasicAuth
#users = [('bob', 'test-pass'), ('jill', 'super-pass')]
#c['status'].append(html.WebStatus(http_port=8020,allowForce=True,auth=BasicAuth(users)))
c['status'].append(html.WebStatus(http_port=8020,allowForce=True))

####### DEBUGGING OPTIONS

# if you set 'debugPassword', then you can connect to the buildmaster with
# the diagnostic tool in contrib/debugclient.py . From this tool, you can
# manually force builds and inject changes, which may be useful for testing
# your buildmaster without actually committing changes to your repository (or
# before you have a functioning 'sources' set up). The debug tool uses the
# same port number as the slaves do: 'slavePortnum'.

#c['debugPassword'] = "123456"

# if you set 'manhole', you can ssh into the buildmaster and get an
# interactive python shell, which may be useful for debugging buildbot
# internals. It is probably only useful for buildbot developers. You can also
# use an authorized_keys file, or plain telnet.
#from buildbot import manhole
#c['manhole'] = manhole.PasswordManhole("tcp:9999:interface=127.0.0.1",
#                                       "admin", "password")


####### PROJECT IDENTITY

# the 'projectName' string will be used to describe the project that this
# buildbot is working on. For example, it is used as the title of the
# waterfall HTML page. The 'projectURL' string will be used to provide a link
# from buildbot HTML pages to your project's home page.

c['projectName'] = "Gulessoft Openembedded Change building"
c['projectURL'] = "http://www.gulessoft.com/"

# the 'buildbotURL' string should point to the location where the buildbot's
# internal web server (usually the html.Waterfall page) is visible. This
# typically uses the port number set in the Waterfall 'status' entry, but
# with an externally-visible host name which the buildbot cannot figure out
# without some help.

c['buildbotURL'] = "http://localhost:8020/"
